<?php 
if (!defined('BASEPATH')){
	exit('No direct script access allowed');
}

/**
 * telecom Controller
 * Build by Phuc Nguyen
 * Contact : nguyenvanphuc0626@gmail.com
 */

class Telecom extends BACKEND_Controller {
	public function __construct() {
		parent::__construct();
		$this->load->language('telecom');
		$this->load->language('button');
		if($this->database_connect_status){
			$this->load->model('telecom_model');
			$this->set_controller('telecom');
			$this->set_model($this->telecom_model);
		}
                $this->load->library('bookinglib');
                $this->bookinglib = new bookinglib();
	}
        
        private function menuTop(){
            $this->load->model('stats_model');
            $user_info                          = $this->stats_model->get_user_info($this->stats_model->get_user_id());
            $this->view_data['role_by_group']   = $user_info['role_list'];
            $this->view_data['username']        = $user_info['username'];
            return $this->view_data;
        }
        
        public function sendsms(){
            $this->menuTop();
            
            if($this->input->server('REQUEST_METHOD')=='POST'){
                $params = array(
                    'u'         =>  'PVVIETBAY',
                    'pwd'       =>  'sj688',
                    'from'      =>  'PVVIETBAY',
                    'phone'     =>  $this->input->post('phone'),
                    'sms'       =>  $this->input->post('message')
                );
                $result     = $this->bookinglib->sendsms($params);
                $response   = json_decode($result);
                
                $this->view_data["telecom"]                             = new stdClass();
                $this->view_data["telecom"]->userid                     = $this->session->userdata['user_id'];
                $this->view_data["telecom"]->phone                      = $this->input->post('phone');
                $this->view_data["telecom"]->message                    = $this->input->post('message');
                $this->view_data["telecom"]->ipaddress                  = $_SERVER['REMOTE_ADDR'];
                $this->view_data["telecom"]->code                       = $response->result;
                $this->view_data["telecom"]->status                     = $response->error;
                $this->view_data["telecom"]->lastupdated                = date('Y-m-d H:i:s',time());
                $this->view_data["telecom"]->agent_code                 = $this->session->userdata['agent_code'];
                
                $query = $this->telecom_model->create($this->view_data["telecom"]);
                if(!$query){
                    die("Insert log telecom fail! Contact Admin!");
                }                
                echo $response->error;exit;
            }
            
            $this->load->view('auth/telecom/send', $this->view_data);
        }
        
        public function saleSms(){
            $this->menuTop();
            if($this->input->server('REQUEST_METHOD')=='POST'){
                $this->view_data['phone'] = ($this->input->post('phone'))?$this->input->post('phone'):'';
                $this->load->view('auth/telecom/saleSms', $this->view_data);
            }
        }
}

/* End of file telecom.php */
/* Location: ./application/controllers/auth/telecom.php */